package adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import androidx.viewpager.widget.PagerAdapter;

//import com.ecdc.touchelx.R;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import utils.OtherUtil;
import utils.ToastUtils;

/**
 * ViewPager适配器
 * Create by: chenwei.li
 * Date: 2017/12/8
 * time: 15:17
 * Email: lichenwei.me@foxmail.com
 */

public class DatePagerAdapter3 extends PagerAdapter {

    private Activity mContext;
//    private CALL_BACK mCALL_BACK;
//
//    public interface CALL_BACK{
//        public void callBackData(int index);
//    }
//GridView dateView;
    public DatePagerAdapter3(Activity context) {
        this.mContext = context;
//        View view=LayoutInflater.from(mContext).inflate(R.layout.view_date,null);
//         dateView= view.findViewById(R.id.gridView);

    }




    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        String ddd="eee";
        int weekday=OtherUtil.getCurrentXingQiJiByDate(ddd.split("～")[0]);
//
        String time=ddd.split("～")[1];
        String days=time.split("-")[2];

        String nian=time.split("-")[0];
        String yue=time.split("-")[1];

        int totalDays=Integer.parseInt(ddd.split("～")[1].split("-")[2]);
//

//        ToastUtils.getToastUtilsInstance().toastCenterStrip("当前位置："+ddd,mContext,Color.GREEN);

        GridView dateView = new GridView(mContext);
        dateView.setNumColumns(7);
        dateView.setHorizontalSpacing(10);
        dateView.setVerticalSpacing(20);

        List<String> list=new ArrayList<>();
        //具体数据@是否显示控件@是否显示边框
        int tian=0;
        if(weekday==1){

            tian=6+totalDays;

        }else if(weekday==2){

            tian=totalDays;

        }else if(weekday==3){

            tian=1+totalDays;


        }else if(weekday==4){
            tian=2+totalDays;


        }else if(weekday==5){
            tian=3+totalDays;


        }else if(weekday==6){
            tian=4+totalDays;


        }else if(weekday==7){
            tian=5+totalDays;
        }
        for(int i=0;i<tian;i++){
            if(weekday==1){
                if(i<6){
                    list.add("--"+totalDays+"@"+"0"+"@"+"1");
                }else {
//                    if(){
//
//                    }
//                    HealthSportEnty mHealthSportEnty=null;
//                    try {
//                        mHealthSportEnty = DbUitls.getDbManager().selector(HealthSportEnty.class).where("time","=",listMonth.get(i)+"").findFirst();
//                    } catch (DbException e) {
//                        e.printStackTrace();
//                    }


                    list.add((i-5)+"@"+"1"+"@"+"0");
                }

            }else if(weekday==2){

                list.add((i+1)+"@"+"1"+"@"+"0");

            }else if(weekday==3){

                if(i<1){
                    list.add("--"+totalDays+"@"+"0"+"@"+"1");
                }else {
                    list.add((i-0)+"@"+"1"+"@"+"0");
                }

            }else if(weekday==4){
                if(i<2){
                    list.add("--"+totalDays+"@"+"0"+"@"+"1");
                }else {
                    list.add((i-1)+"@"+"1"+"@"+"0");
                }

            }else if(weekday==5){
                if(i<3){
                    list.add("--"+totalDays+"@"+"0"+"@"+"1");
                }else {
                    list.add((i-2)+"@"+"1"+"@"+"0");
                }
            }else if(weekday==6){
                if(i<4){
                    list.add("--"+totalDays+"@"+"0"+"@"+"1");
                }else {
                    list.add((i-3)+"@"+"1"+"@"+"0");
                }
            }else if(weekday==7){
                if(i<5){
                    list.add("--"+totalDays+"@"+"0"+"@"+"1");
                }else {
                    list.add((i-4)+"@"+"1"+"@"+"0");
                }

            }

        }
        DateAdapter ADAPTER=new DateAdapter(mContext,list,ddd);
        dateView.setAdapter(ADAPTER);
        container.addView(dateView);
        return dateView;


    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        String ddd=getDateData(2,HealthBodyActivity.MAX_PAGE_COUNTS-1-position);
//        ToastUtils.getToastUtilsInstance().toastCenterStrip(HealthBodyActivity.MAX_PAGE_COUNTS+"当前位置2："+position,mContext,Color.GREEN);
//
//        container.removeView((View) object);
    }


    /**
     * 当滑动view的时候，获取日期数据
     * @param style
     */
    private String  getDateData(int style,int se){
        String content=null;
        if(style==1){//周
            try {
                content = OtherUtil.getMondayToWeekdayByLastWeek(new Date(), se);
            } catch (ParseException e) {
                e.printStackTrace();
            }


        }else  if(style==2){//月
            content = OtherUtil.getMonthByCurrentTime(new Date(), se);
        }else  if(style==3){//年
            content = OtherUtil.getYear(new Date(), se);
        }

        return content;

    }


}
